package com.rayo.accesscontrollercopy.model.biz;


import com.rayo.accesscontrollercopy.config.GlobalVariables;
import com.rayo.accesscontrollercopy.model.callback.OnGetDbListener;
import com.rayo.accesscontrollercopy.model.callback.OnUpdateDbListener;
import com.rayo.accesscontrollercopy.model.db.bean.ReaderData;
import com.rayo.accesscontrollercopy.model.db.dao.ReaderDataDao;
import com.rayo.accesscontrollercopy.model.db.dao.ReaderDataImpl;

/**
 * Created by yanghaojie on 16/7/26.
 */
public class BeepBiz implements IBeepBiz {
    private ReaderDataDao readerDataDao = new ReaderDataImpl();

    @Override
    public void init(OnGetDbListener onGetDbListener) {
        if (null != GlobalVariables.getInstance().getmReaderData()) {
//            onGetDbListener.onSuccess(GlobalVariables.getInstance().getmReaderData());
        } else {
            ReaderData readerData = readerDataDao.findFirst();
            if (null == readerData) {
                readerData = new ReaderData();
                readerDataDao.addReader(readerData);
            }
            GlobalVariables.getInstance().setmReaderData(readerData);
//            onGetDbListener.onSuccess(readerData);
        }
    }

    @Override
    public void save(ReaderData readerData, OnUpdateDbListener onUpdateDbListener) {
        readerDataDao.updateReader(readerData);
        GlobalVariables.getInstance().setmReaderData(readerData);
//        onUpdateDbListener.onSuccess(readerData);
    }
}
